#include "comm.hpp"

extern Log log;

int main()
{
    int shmid = CreateShm();
    char *shmaddr = (char*)shmat(shmid, nullptr, 0);

    // ipc code 在这里！！
    // 一旦有人把数据写入到共享内存，其实我们立马能看到了！！
    // 不需要经过系统调用，直接就能看到数据了！
    struct shmid_ds shmds;
    while(true)
    {
        cout << "client say@ " << shmaddr << endl; //直接访问共享内存
        sleep(1);

        shmctl(shmid, IPC_STAT, &shmds);
        cout << "shm size: " << shmds.shm_segsz << endl;
        cout << "shm nattch: " << shmds.shm_nattch << endl;
        printf("shm key: 0x%x\n",  shmds.shm_perm.__key);
        cout << "shm mode: " << shmds.shm_perm.mode << endl;
    }

    shmdt(shmaddr);
    shmctl(shmid, IPC_RMID, nullptr);
    return 0;
}
